
package com.platform.modules.mall.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.platform.common.utils.Query;
import com.platform.modules.mall.dao.MallAssociTagDao;
import com.platform.modules.mall.entity.MallAssociTagEntity;
import com.platform.modules.mall.service.MallAssociTagService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * 店铺或者商品的标签Service实现类
 *
 * @author 
 * @date 2022-07-06 11:08:16
 */
@Service("mallAssociTagService")
public class MallAssociTagServiceImpl extends ServiceImpl<MallAssociTagDao, MallAssociTagEntity> implements MallAssociTagService {

    @Override
    public boolean delateByAssoci(String associId, String... otherId) {
        return this.lambdaUpdate()
                .eq(MallAssociTagEntity::getAssociId,associId)
                .in(otherId != null,MallAssociTagEntity::getOtherId,otherId)
                .remove();
    }

    @Override
    public List<MallAssociTagEntity> getByAssoci(String associId) {
        return this.lambdaQuery()
                .select(MallAssociTagEntity::getTitle,
                        MallAssociTagEntity::getDescribe,
                        MallAssociTagEntity::getType)
                .eq(MallAssociTagEntity::getAssociId,associId)
                .page(new Page<>(0,3)).getRecords();
    }

    @Override
    public boolean delateByOtherId(String otherId, String... associId) {
        if(associId != null && associId.length > 0){
            return this.lambdaUpdate()
                    .in(associId != null,MallAssociTagEntity::getAssociId,associId)
                    .eq(MallAssociTagEntity::getOtherId,otherId)
                    .remove();
        }

        return true;
    }

    @Override
    public List<MallAssociTagEntity> queryAll(Map<String, Object> params) {
        return baseMapper.queryAll(params);
    }

    @Override
    public Page queryPage(Map<String, Object> params) {
        //排序
        params.put("sidx", "T.id");
        params.put("asc", false);
        Page<MallAssociTagEntity> page = new Query<MallAssociTagEntity>(params).getPage();
        return page.setRecords(baseMapper.selectMallAssociTagPage(page, params));
    }

    @Override
    public boolean add(MallAssociTagEntity mallAssociTag) {
        mallAssociTag.setCreateTime(new Date());
        return this.save(mallAssociTag);
    }

    @Override
    public boolean update(MallAssociTagEntity mallAssociTag) {
        return this.updateById(mallAssociTag);
    }

    @Override
    public boolean delete(String id) {
        return this.removeById(id);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean deleteBatch(String[] ids) {
        return this.removeByIds(Arrays.asList(ids));
    }
}
